<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        var arr = [
            { name: '王宝宝1' },
            { name: '王宝宝2' },
            { name: '王宝宝3' },
            { name: '王宝宝4' }
        ]
        for (var i = 0; i < arr.length; i++) {
            arr[i].SayHi = function () {
                console.log(this.name + ':hello');

            }
            console.log(arr[i]);

        }
        for (var j = 0; j < arr.length; j++) {
            arr[j].SayHi();
        }


    </script>
</body>

</html>